Completed
Push — master ( 0669d1...20d753 )
by Dimas
09:15 queued 01:26
created

sync   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 3
1
import Config from "./Config";
2
import * as upath from "upath";
3
import * as fs from "fs";
4
import * as process from "process";
5
import chokidar from "chokidar";
6
import observatory from "../observatory/ts/observatory";
7
import { Client } from "scp2";
8
import { readFileSync } from "fs";
9
import sftp from "./sftp";
10
11
export default class sync {
12
  config: Config;
13
  task: any;
14
  client: Client;
15
  sftp: sftp;
16
17
  constructor() {
18
    this.task = observatory.add("Initializing...");
19
20
    // Get config
21
    this.config = new Config();
22
    this.task.status("reading config");
23
24
    this.config
25
      .ready()
26
      .then(() => {
27
        // Get Command line interface
28
        //this.cli.write("Connecting");
29
        //this.cli.startProgress();
30
        this.task.status("watching files");
31
32
        var ori = this.config.localPath;
33
        var root = process.cwd();
34
        if (upath.isAbsolute(this.config.localPath)) {
35
          var mod = upath.normalizeSafe(
36
            this.config.localPath.replace(root, "")
37
          );
38
          if (mod == ori) {
39
            throw new Error("Cannot find absolute path");
40
          } else {
41
            this.config.localPath = "." + mod;
42
          }
43
        }
44
45
        this.config.localPath = upath.normalizeSafe(this.config.localPath);
46
        fs.exists(this.config.localPath, function (es) {
47
          if (!es) {
48
            throw new Error("Local path not exists");
49
          }
50
        });
51
52
        this.sftp = new sftp(this.config);
53
54
        return true;
55
      })
56
      .then(async () => {
57
        this.task.status("connecting server");
58
59
        const any = await this.sftp.connect();
60
        //this.task.done(any).details(this.config.host);
61
        console.log(this.sftp.local.fetch());
62
        //console.log(this.config.ignores);
63
      });
64
  }
65
}
66